//
//  LSZMyIntegralViewController.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/9/2.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZMyIntegralViewController.h"

@interface LSZMyIntegralViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tableViewMyIntegral;
@property(nonatomic,strong) LSZMyPointsManager * myPointsManager;
@property(nonatomic,assign) BOOL isOK;
@end

@implementation LSZMyIntegralViewController
-(void)intWithData
{
    [LSZRequestDicData initWithMyPoints:^(BOOL isOk, NSString * string, LSZMyPointsManager * manager) {
        if (isOk == YES) {
            self.isOK = YES;
            self.myPointsManager = manager;
            [self.tableViewMyIntegral reloadData];
        }else{
            self.isOK = NO;
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZMyIntegralViewController"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }
    }];
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
-(void)addNotificationCenter
{
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZMyIntegralViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.isOK = NO;
    [self intWithData];
    [self addNotificationCenter];
    [self.tableViewMyIntegral registerClass:[LSZMyScoreTableViewCell class] forCellReuseIdentifier:@"LSZMyScoreTableViewCell"];
    [self.tableViewMyIntegral registerClass:[LSZTypeLabelTableViewCell class] forCellReuseIdentifier:@"LSZTypeLabelTableViewCell"];
    [self.tableViewMyIntegral registerClass:[LSZVariousRankingDataTableViewCell class] forCellReuseIdentifier:@"LSZVariousRankingDataTableViewCell"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (self.isOK == YES) {
        return 2;
    }else{
        return 0;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else{
        return 1+self.myPointsManager.arrayData.count;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.001;
    }else{
        return 10;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 150;
    }else{
        return 50;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        LSZMyScoreTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZMyScoreTableViewCell" forIndexPath:indexPath];
        cell.labelRanking.text = [NSString stringWithFormat:@"我的排名:%@",self.myPointsManager.scoreRanking];
        cell.labelNumber.text = [NSString stringWithFormat:@"我的得分:%@",self.myPointsManager.totalScore];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        if (indexPath.row == 0) {
            LSZTypeLabelTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZTypeLabelTableViewCell" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else{
            LSZVariousRankingDataTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZVariousRankingDataTableViewCell" forIndexPath:indexPath];
            LSZMyPointsMg * mg = nil;
            mg = self.myPointsManager.arrayData[indexPath.row-1];
            cell.myPointsMg = mg;
            cell.labelNum.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
    }
}
-(UITableView *)tableViewMyIntegral
{
    if (_tableViewMyIntegral == nil) {
        _tableViewMyIntegral = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-44) style:UITableViewStyleGrouped];
        _tableViewMyIntegral.delegate = self;
        _tableViewMyIntegral.dataSource = self;
        _tableViewMyIntegral.estimatedRowHeight=0;
        _tableViewMyIntegral.estimatedSectionFooterHeight =0;
        _tableViewMyIntegral.estimatedSectionHeaderHeight =0;
        [_tableViewMyIntegral setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewMyIntegral];
    }
    return _tableViewMyIntegral;
}

@end
